package borge.web.teamspirit.client.page.team.widgets;

import java.util.List;

import borge.web.teamspirit.client.TeamSpirit;
import borge.web.teamspirit.client.TeamSpiritConstants;
import borge.web.teamspirit.client.data.TeamSerieInfo;
import borge.web.teamspirit.client.interfaces.PersistentData;
import borge.web.teamspirit.client.interfaces.ServerCallbackHandler;
import borge.web.teamspirit.client.interfaces.WidgetEventHandler;
import borge.web.teamspirit.client.interfaces.PersistentData.DataKey;
import borge.web.teamspirit.client.interfaces.WidgetEventHandler.WidgetEventType;
import borge.web.teamspirit.client.page.shared.widgets.ListDataWidget;
import borge.web.teamspirit.client.page.team.TokenData;

import com.google.gwt.user.client.ui.Hyperlink;


/**
 * Display a list of series
 * @author andreas
 *
 */
@SuppressWarnings("unchecked")
public class ListSeriesWidget extends ListDataWidget<TeamSerieInfo> {
	
	//private List<Serie> iSeries;
	
	public ListSeriesWidget(WidgetEventHandler aEventHandler, List<TeamSerieInfo> aSerieInfo){
		
	    super(aEventHandler, aSerieInfo, DataKey.SERIE, TokenData.assembleTeamToken(TokenData.EDIT, TokenData.SERIE), 
	            WidgetEventType.DELETE_SERIE,
	              TokenData.assembleTeamToken(TokenData.SHOW, TokenData.SERIE));
		//iData = aSeries;

		// populate table with series information
		createDataTable();
		
		initWidget(iPanel);
		
	}
	
	protected void createDataTable(){
	 
	    reset();
        
        TeamSpiritConstants lcs = TeamSpirit.getConstants();
        int row = 0;
        int column = 0;
        
        for(TeamSerieInfo tsi : iData){
        	
        	String text = tsi.getAssociationName() + ":" + tsi.getSport() + ":" + tsi.getLeagueSeason() + ":" + tsi.getLeagueDivision();
        	iTable.setWidget(row++, column, new Hyperlink(text, TokenData.assembleTeamToken(TokenData.SHOW, TokenData.SERIE, tsi.getSerieKey())));
        }
	}
	
	@Override
	public void requestServerData(ServerCallbackHandler aHandler) {
		
//		DBQuery query = new DBQuery(DataKey.SERIE, Serie.class.getName());
//		query.addFilter("iTeamKey", DBQuery.EQUALS, "teamKey", "String", SessionData.sCurrentTeam.getEncodedKey(), null);
//		ServerComm.getObjectList(query, aHandler);
	}
}
